﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using WPFTestSolution.Pages;
using WPFTestSolution.Pages.Controls;
using WPFTestSolution.Pages.Controls.ContentControls;
using WPFTestSolution.Pages.Controls.ContentControls.ButtonBases;
using WPFTestSolution.Pages.Controls.ContentControls.ButtonBases.ToggleButtons;
using WPFTestSolution.Pages.Controls.ItemsControls;
using WPFTestSolution.Pages.Controls.ItemsControls.ListBoxes;
using WPFTestSolution.Pages.Controls.ItemsControls.MenuBases;
using WPFTestSolution.Pages.Controls.ItemsControls.Selectors;
using WPFTestSolution.Pages.Controls.ItemsControls.Selectors.MultiSelectors;
using WPFTestSolution.Pages.Controls.RangeBases;
using WPFTestSolution.Pages.Controls.TextBoxBases;
using WPFTestSolution.Pages.Decorators;
using WPFTestSolution.Pages.Panels;
using WPFTestSolution.Windows;

namespace WPFTestSolution {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow {

        public MainWindow() {
            InitializeComponent();
            this.Title = "WPF Demo";

            Console.WriteLine("0.MainWindow 进入了构造方法");
            this.SourceInitialized += (sender, args) => Console.WriteLine("1.SourceInitialized 被触发");
            this.Activated += (sender, args) => Console.WriteLine("2.Activated 被触发");
            this.Loaded += (sender, args) => Console.WriteLine("3.Loaded 被触发");
            this.ContentRendered += (sender, args) => Console.WriteLine("4.ContentRendered 被触发");
            this.Deactivated += (sender, args) => Console.WriteLine("5.Deactivated 被触发");
            this.Closing += (sender, args) => Console.WriteLine("6.Closing 被触发");
            this.Closed += (sender, args) => Console.WriteLine("7.Closed 被触发");
            this.Unloaded += (sender, args) => Console.WriteLine("8.Unloaded 被触发");
            Console.WriteLine();
        }

        private void OnTreeViewItemClick(object sender, MouseButtonEventArgs e) {
            Console.WriteLine($"sender = {sender}, e = {e}");
            if (!(sender is TreeViewItem treeViewItem)) return;
            string name = treeViewItem.Name;
            this.Title = treeViewItem.Header.ToString();

            //017-Panel基类 简介
            if (name == this.Btn_Panel_Introduce.Name) {
                this.ContentFrame.Navigate(new _17_Panel_Introduce_Page());
                return;
            }
            //018-Grid控件（网格布局）
            if (name == this.Btn_Grid.Name) {
                this.ContentFrame.Navigate(new _18_Grid_Page());
                return;
            }
            //019-UniformGrid控件（均分布局）
            if (name == this.Btn_UniformGrid.Name) {
                this.ContentFrame.Navigate(new _19_UniformGrid_Page());
                return;
            }
            //020-StackPanel控件（堆式布局）
            if (name == this.Btn_StackPanel.Name) {
                this.ContentFrame.Navigate(new _20_StackPanel_Page());
                return;
            }
            //021-WrapPanel控件（瀑布流布局）
            if (name == this.Btn_WrapPanel.Name) {
                this.ContentFrame.Navigate(new _21_WrapPanel_Page());
                return;
            }
            //022-DockPanel控件（停靠布局）
            if (name == this.Btn_DockPanel.Name) {
                this.ContentFrame.Navigate(new _22_DockPanel_Page());
                return;
            }
            //023-Canvas控件（绝对布局）
            if (name == this.Btn_Canvas.Name) {
                this.ContentFrame.Navigate(new _23_Canvas_Page());
                return;
            }
            //025-WPF布局Demo示例
            if (name == this.Btn_Layout_Demo.Name) {
                this.ContentFrame.Navigate(new _25_PanelLayoutDemo_Page());
                return;
            }
            //TabPanel 还未学!
            if (name == this.Btn_TabPanel.Name) {
                MessageBox.Show("还未学习!!!");
                return;
            }
            
            //024-Border装饰器（边框装饰器）
            if (name == this.Btn_Border.Name) {
                this.ContentFrame.Navigate(new _24_Border_Page());
                return;
            }
            
            //027-Control基类
            if (name == this.Btn_Control_Introduce.Name) {
                this.ContentFrame.Navigate(new _27_Control_Page());
                return;
            }
            //026-GridSplitter(: Thumb : Control)分割窗口
            if (name == this.Btn_GridSplitter.Name) {
                this.ContentFrame.Navigate(new _26_GridSplitter_Page());
                return;
            }
            //027-Control基类(: FrameworkElement)
            if (name == this.Btn_Control.Name) {
                this.ContentFrame.Navigate(new _27_Control_Demo_Page());
                return;
            }
            //028-ContentControl(: Control, 内容控件)
            if (name == this.Btn_ContentControl_Introduce.Name) {
                this.ContentFrame.Navigate(new _28_ContentControl_Page());
                return;
            }
            //029-ButtonBase(: ContentControl, 是一个抽象类)
            if (name == this.Btn_ButtonBase.Name) {
                this.ContentFrame.Navigate(new _29_ButtonBase_Page());
                return;
            }
            //030-Button按钮(: ButtonBase)
            if (name == this.Btn_Button.Name) {
                this.ContentFrame.Navigate(new _30_Button_Page());
                return;
            }
            //031-ToggleButton基类(: ButtonBase)
            if (name == this.TB_ToggleButton.Name) {
                this.ContentFrame.Navigate(new _31_ToggleButton_Page());
                return;
            }
            //032-CheckBox复选框
            if (name == this.Btn_CheckBox.Name) {
                this.ContentFrame.Navigate(new _32_CheckBox_Page());
                return;
            }
            //033-RadioButton单选框
            if (name == this.Btn_RadioButton.Name) {
                this.ContentFrame.Navigate(new _33_RadioButton_Page());
                return;
            }
            //034-RepeatButton重复按钮(: ButtonBase)
            if (name == this.RB_RepeatButton.Name) {
                this.ContentFrame.Navigate(new _34_RepeatButton_Page());
                return;
            }
            //035-Label 标签(: ContentControl)
            if (name == this.Btn_Label.Name) {
                this.ContentFrame.Navigate(new _35_Label_Page());
                return;
            }
            //039-ToolTip控件(: ContentControl, 提示工具)
            if (name == this.Btn_ToolTip.Name) {
                this.ContentFrame.Navigate(new _39_ToolTip_Page());
                return;
            }
            //042-GroupBox标题容器控件(: ContentControl)
            if (name == this.Btn_GroupBox.Name) {
                this.ContentFrame.Navigate(new _42_GroupBox_Page());
                return;
            }
            //043-ScrollViewer控件(: ContentControl)
            if (name == this.Btn_ScrollViewer.Name) {
                this.ContentFrame.Navigate(new _43_ScrollViewer_Page());
                return;
            }
            //049-Expander折叠控件(: HeaderedContentControl : ContentControl)
            if (name == this.Btn_Expander.Name) {
                this.ContentFrame.Navigate(new _49_Expander_Page());
                return;
            }
            
            //037-038, TextBoxBase(: Control, 输入控件)
            if (name == this.Btn_TextBoxBase.Name) {
                this.ContentFrame.Navigate(new _37_TextBoxBase_Page());
                return;
            }
            //037-TextBox文本(输入)框
            if (name == this.Btn_TextBox.Name) {
                this.ContentFrame.Navigate(new _37_TextBox_Page());
                return;
            }
            //038-RichTextBox富文本(输入)框
            if (name == this.Btn_RichTextBox.Name) {
                this.ContentFrame.Navigate(new _38_RichTextBox_Page());
                return;
            }
            //044-RangeBase(: Control)简介
            if (name == this.Btn_RangeBase_Introduce.Name) {
                this.ContentFrame.Navigate(new _44_RangeBase_Page());
                return;
            }
            //044-ScrollBar滚动条(: RangeBase: Control)
            if (name == this.Btn_ScrollBar.Name) {
                this.ContentFrame.Navigate(new _44_ScrollBar_Page());
                return;
            }
            //045-Slider滑动条
            if (name == this.Btn_Slider.Name) {
                this.ContentFrame.Navigate(new _45_Slider_Page());
                return;
            }
            //046-ProgressBar进度条(: RangeBase: Control)
            if (name == this.Btn_ProgressBar.Name) {
                this.ContentFrame.Navigate(new _46_ProgressBar_Page());
                return;
            }
            
            //047-Calendar日历控件(: Control)
            if (name == this.Btn_Calendar.Name) {
                this.ContentFrame.Navigate(new _47_Calendar_Page());
                return;
            }
            //048-DatePicker日期控件(: Control)
            if (name == this.Btn_DatePicker.Name) {
                this.ContentFrame.Navigate(new _48_DatePicker_Page());
                return;
            }
            
            //051-ItemsControl集合控件基类简介(: Control)
            if (name == this.Btn_ItemsControl_Introduce.Name) {
                this.ContentFrame.Navigate(new _51_ItemsControl_Page());
                return;
            }
            
            //052-Selector基类(: ItemsControl)
            if (name == this.Btn_Selector_Introduce.Name) {
                this.ContentFrame.Navigate(new _52_Selector_Page());
                return;
            }
            //053-ListBox列表控件
            if (name == this.Btn_ListBox.Name) {
                this.ContentFrame.Navigate(new _53_ListBox_Page());
                return;
            }
            //054-ListView数据列表控件(: ListBox)
            if (name == this.Btn_ListView.Name) {
                this.ContentFrame.Navigate(new _54ListView_Page());
                return;
            }
            
            //055-MultiSelector(: Selector)
            if (name == this.Btn_MultiSelector.Name) {
                this.ContentFrame.Navigate(new _55_MultiSelector_Page());
                return;
            }
            //055-DataGrid数据表格控件(: MultiSelector)
            if (name == this.Btn_DataGrid.Name) {
                this.ContentFrame.Navigate(new _55_DataGrid_Page());
                return;
            }
            //056-ComboBox下拉框控件(: Selector)
            if (name == this.Btn_ComboBox.Name) {
                this.ContentFrame.Navigate(new _56_ComboBox_Page());
                return;
            }
            //057-TabControl控件(: Selector)
            if (name == this.Btn_TabControl.Name) {
                this.ContentFrame.Navigate(new _57_TabControl_Page());
                return;
            }
            
            //058-TreeView树控件(: ItemsControl)
            if (name == this.Btn_TreeView.Name) {
                this.ContentFrame.Navigate(new _58_TreeView_Page());
                return;
            }
            //059-Menu菜单(: MenuBase : ItemsControl)
            if (name == this.Btn_Menu.Name) {
                this.ContentFrame.Navigate(new _59_Menu_Page());
                return;
            }
            //060-ContextMenu上下文菜单(: MenuBase : ItemsControl)
            if (name == this.Btn_ContextMenu.Name) {
                this.ContentFrame.Navigate(new _60_ContextMenu_Page());
                return;
            }
            //061-StatusBar状态栏(: ItemsControl)
            if (name == this.Btn_StatusBar.Name) {
                this.ContentFrame.Navigate(new _61_StatusBar_Page());
                return;
            }
            
            //03? PasswordBox(: Control, 密码输入控件)
            if (name == this.Btn_PasswordBox.Name) {
                MessageBox.Show("还未学习!!!");
                return;
            }
            
            //036-TextBlock文字块(: FrameworkElement)
            if (name == this.Btn_TextBlock.Name) {
                this.ContentFrame.Navigate(new _36_TextBlock_Page());
                return;
            }
            //040-Popup弹出窗口(: FrameworkElement)
            if (name == this.Btn_Popup.Name) {
                this.ContentFrame.Navigate(new _40_Popup_Page());
                return;
            }
            //041-Image图像控件(: FrameworkElement)
            if (name == this.Btn_Image.Name) {
                this.ContentFrame.Navigate(new _41_Image_Page());
                return;
            }
            //050-MediaElement媒体播放器(: FrameworkElement)
            if (name == this.Btn_MediaElement.Name) {
                this.ContentFrame.Navigate(new _50_MediaElement_Page());
                return;
            }
        }
        
        private void OnButtonClick(object sender, RoutedEventArgs e) {
            Console.WriteLine($"sender = {sender}, e = {e}");
            if (!(sender is Button button)) return;
            string name = button.Name;
                
            //测试
            if (name == this.Button_Test.Name) {
                new TestWindow().Show();
            }
        }
    }
}